package cn.agrael.struts.plugin.ejb3;

import javax.annotation.Resource;
import javax.ejb.EJB;

import cn.agrael.util.ConstantMap;
import cn.agrael.util.ConstantUtils;
import cn.agrael.util.ObjectUtils;
import cn.agrael.util.StringUtils;

import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
 * 插件常量，对应着配置文件中的信息。
 * 
 * @author <a href="mailto:agraellee@gmail.com">Agrael·Lee</a>
 * 
 */
public final class StrutsEJBPluginConstant {

	/** 插件配置信息 */
	private static final ConstantMap PLUGIN_CONFIG = ConstantUtils.appendConstant(
			ConstantUtils.buildConstantMap("cn/agrael/struts/plugin/ejb3/default-struts-ejb3-plugin.properties"),
			"struts-ejb3-plugin.properties");
	/** ENC路径名 */
	public static final String ENC_PATH = PLUGIN_CONFIG.get("ENCPath");
	/** EJB容器类型 */
	public static final ApplicationServer EJB_CONTAINER;
	/** 是否解析 {@link Resource} */
	public static final String IS_PARSE_RESOURCE_ANNOTATION = StringUtils.checkEmptyString(PLUGIN_CONFIG.get("isParseResource"), "false");
	/** 是否解析 {@link EJB} */
	public static final String IS_PARSE_EJB_ANNOTATION = StringUtils.checkEmptyString(PLUGIN_CONFIG.get("isParseEJB"), "true");
	/** EJB资源启始路径 */
	public static final String EAR_FILE_BASE_NAME = StringUtils.checkEmptyString(PLUGIN_CONFIG.get("earFileBaseName"), "");
	/** JNDI 路径分割符 */
	public static final String JNDI_PATH_DELIMITER = "/";
	/** 远程bean JNDI获取字符串 */
	public static final String REMOTE = StringUtils.checkEmptyString(PLUGIN_CONFIG.get("remote"), "remote");
	/** 本地bean JNDI获取字符串 */
	public static final String LOCAL = StringUtils.checkEmptyString(PLUGIN_CONFIG.get("local"), "local");
	/** Interceptor 动态代理创建时的接口 */
	public static final Class<?>[] INTERCEPTOR_INTERFACES = new Class[] { Interceptor.class };
	/** ActionProxy 动态代理创建时的接口 */
	public static final Class<?>[] ACTION_PROXY_INTERFACES = new Class[] { ActionProxy.class };

	static {
		ApplicationServer o = null;
		try {
			o = ObjectUtils.<ApplicationServer> createObject(PLUGIN_CONFIG.get("ejbContainer"));
		} catch (Exception e) {
			new Error("创建 [ApplicationServer] 的实例时发生错误。", e);
		} finally {
			EJB_CONTAINER = o;
			o = null;
		}
	}

	private StrutsEJBPluginConstant() {
	}
}
